/**
 * 
 */
package com.xmlmod.util;

import java.io.File;
import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

/**
 * @author dmadmin
 *
 */
public class LoadDocument {
	public static Document loadXMLDocument(String filePath) throws ParserConfigurationException, SAXException, IOException{
		File file = new File(filePath);
		if(file != null && file.exists()){
			if(file.canWrite()){
				DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
				
				dbf.setValidating(false);
				dbf.setNamespaceAware(true);
				
				DocumentBuilder db = dbf.newDocumentBuilder();
				Document doc = db.parse(file);
				return doc;
			}else{
				System.out.println("File " + filePath + " is read-only.  No action performed");
				return null;
			}
		}else{
			System.out.println("File " + filePath + " not found.  No action performed");
			return null;
		}
	}
	
	
}
